﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CM_GetOuterFeeBySellmanID]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CM_GetOuterFeeBySellmanID];
GO
CREATE PROCEDURE [dbo].[sproc_CM_GetOuterFeeBySellmanID]
@sellmanid int,
@begintime datetime,
@endtime datetime
AS
    SELECT sum(fee) as fee
    FROM UDS_CM_ClientContact
    WHERE MarketmanID=@sellmanid
    AND patindex('%outer%',feeused)>=0
    AND contacttime between @begintime and dateadd(day,1,@endtime)